#!/bin/dash
# Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Extra crosh commands

if [ "$(basename $0)" = "crosh-workarounds" ]; then
  exec "$(dirname $0)/crosh" --workarounds
fi

HELP_ADVANCED="$HELP_ADVANCED"'
 cryptohome [--status]
  Get human-readable status information from cryptohomed
'
cmd_cryptohome() {
  local cryptohome="/usr/sbin/cryptohome"
  if [ ! -f $cryptohome ]; then
    echo "Missing $cryptohome" >&2
  else
    case x"$1" in
             x--status|x)
                $cryptohome --action=status
                ;;
             *)
                echo "Usage: cryptohome [--status]" >&2
    esac
  fi
}

HELP_ADVANCED="$HELP_ADVANCED"'
 wlan_bgscan [--short secs] [--long secs] [--signal dBm] [<algorithm>]
  Set/display WiFi background scan parameters.
'

cmd_wlan_bgscan() {
  local options=""

  while [ "$(echo "$1" | cut -c1-2)" = "--" ]; do
    # Do just enough parsing to filter/map options; we
    # depend on ping to handle final validation
    if [ "$1" = "--short" ]; then
      shift; options="$options BgscanShortInterval=$1"
    elif [ "$1" = "--long" ]; then
      shift; options="$options ScanInterval=$1"
    elif [ "$1" = "--signal" ]; then
      shift; options="$options BgscanSignalThreshold=$1"
    else
      echo "Unknown option: $1"
      return 1
    fi

    shift
  done

  if [ -n "$1" ]; then
    options="$options BgscanMethod=$1"
  fi

  /usr/local/lib/flimflam/test/set-bgscan $options
  # NB: parameters do not take effect until next association
}
